#include <iostream>
#include <fermat/common/linenoise.h>
using std::cout;
using std::endl;

void defualt_callbak(const char* editBuffer, std::vector<std::string>& completions) 
{
    if (editBuffer[0] == 'h') {
        completions.push_back("hello");
        completions.push_back("hello there");
    }
}

int main(int argc, const char** argv)
{
    const char *path = "history.txt";

    // Enable the multi-line mode
    fermat::linenoise::SetMultiLine(true);

    // Set max length of the history
    fermat::linenoise::SetHistoryMaxLen(4);

    // Setup completion words every time when a user types
    fermat::linenoise::SetCompletionCallback(std::bind(defualt_callbak, std::placeholders::_1, std::placeholders::_2));

    // Load history
    fermat::linenoise::LoadHistory(path);

    while (true) {
        std::string line;
        bool quit = fermat::linenoise::Readline("\033[32mfermat-->\x1b[0m> ", line);

        if (quit) {
            break;
        }

        cout <<  "echo: '" << line << "'" << endl;

        // Add line to history
        fermat::linenoise::AddHistory(line.c_str());

        // Save history
        fermat::linenoise::SaveHistory(path);
    }

    return 0;
}
